//
//  EmojiAttachement.swift
//  EmojiKeyBoard
//
//  Created by macs on 15/11/21.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

import UIKit

class EmojiAttachement: NSTextAttachment {
    
    var chs : String?
    
    //获取属性文本
    func emojiGetImageText(emoji : Emoji, font : UIFont) -> NSAttributedString {
        
        image = UIImage(contentsOfFile: emoji.imagePath ?? "")
        chs = emoji.chs
        //设置附件大小
        let lineHight = font.lineHeight
        bounds = CGRect(x: 0, y: -4, width: lineHight, height: lineHight)
        //将附件转为属性文本
//        let imageText = NSAttributedString(attachment: self)
        let imageText = NSMutableAttributedString(attributedString: NSAttributedString(attachment: self))
        imageText.addAttribute(NSFontAttributeName, value: font, range: NSRange(location: 0,length: 1))
        //获取 textView 属性文本
        return imageText
        
    }
    
}
